-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Provide fallback for Observation KeyValues #5020
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Provide fallback for Observation KeyValues #5020
Conversation
* @return key value | ||
*/ | ||
public KeyValue withOptionalValue(@Nullable String value) { | ||
return withValue(ObjectUtils.isEmpty(value) ? KeyValue.NONE_VALUE : value); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if "UNKNOWN" is a better default value for most of these rather than none.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would like to have a bit more encapsulated API for a more declarative approach to reduce the likelihood for using the API wrong. Something along the lines of:
// TODO: it would be nice to have a getKeyName() method returning KeyName from KeyValue for usage in e.g. KeyName[] getLowCardinalityKeyNames()
static KeyValue DB_SYSTEM = KeyValue.of("db.system", "mongodb");
static SmartKeyName<ConnectionString> DB_CONNECTION_STRING = SmartKeyName.required("db.connection_string",
ConnectionString::getConnectionString);
later:
@Nullable ConnectionString connectionString = context.getConnectionString();
KeyValues keyValues = KeyValues.of(MongoObservation.DB_SYSTEM,
MongoObservation.DB_CONNECTION_STRING.valueOf(connectionString));
You can find SmartKeyName
(needs probably a better name) at
https://gist.github.com/mp911de/6729ca327326d072820a1a0eb225c4a6
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if "UNKNOWN" is a better default value for most of these rather than none.
I think so, I can also make the fallback mandatory so it needs to be decided for every key-value.
I would like to have a bit more encapsulated API for a more declarative approach [...]
We can consider improving on this in Micrometer 1.16 (let me talk to @shakuzen about it) but I think this should be considered as a bug and should be fixed in earlier versions where Micrometer 1.16 will not be available I think (unless you want to copy some code from there).
} | ||
} | ||
|
||
return keyValues; | ||
return KeyValues.of( | ||
DB_SYSTEM.withValue("mongodb"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see your approach and I like it more than concatenating KeyValues
. With a refined approach regarding value extraction, we might get a chance for improvement.
Similarly to #4994 this PR adds a fallback value to all the
KeyValue
s used byDefaultMongoHandlerObservationConvention
.TODO:
4.4.x